package cn.frank.framework.caesar.module.ai.qwen.conf.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.HeaderParameter;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;


/**
 * @author renjy
 * @since 2025/6/6 9:03:05
 */
@EnableKnife4j
@Configuration
@Slf4j
public class Knife4jConfig {


    // @Bean(value = "defaultApi2")
    // public Docket defaultApi2() {
    //     Docket docket = new Docket(DocumentationType.SWAGGER_2)
    //             .apiInfo(apiInfo())
    //             // 分组名称
    //             .groupName("测试分组")
    //             .select()
    //             // 这里指定Controller扫描包路径
    //             .apis(RequestHandlerSelectors.basePackage("cn.frank.framework.caesar.module.ai.qwen.rest"))
    //             //.paths(PathSelectors.ant("/app/motorVehicleTactics/**"))
    //             .paths(PathSelectors.any())
    //             .build();
    //     return docket;
    // }
    //
    //
    // private ApiInfo apiInfo() {
    //     return new ApiInfoBuilder()
    //             .title("Frank 我的工具包 ！！！")
    //             .description("Frank RESTful APIs")
    //             .termsOfServiceUrl("https://gitee.com/frank_ren")
    //             .contact("387776286@qq.com")
    //             .version("1.0")
    //             .build();
    // }


    @Bean
    public GroupedOpenApi userApi() {
        String[] paths = {"/**"};
        String[] packagedToMatch = {"cn.frank.framework.caesar.module.ai.qwen.rest"};
        return GroupedOpenApi.builder().group("xx模块")
                .pathsToMatch(paths)
                .addOperationCustomizer((operation, handlerMethod) -> {
                    return operation.addParametersItem(new HeaderParameter().name("groupCode").example("测试").description("集团code").schema(new StringSchema()._default("BR").name("groupCode").description("集团code")));
                })
                .packagesToScan(packagedToMatch).build();
    }

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("XXX系统API")
                        .version("1.0")
                        .description("Knife4j集成springdoc-openapi示例")
                        .termsOfService("http://doc.xiaominfo.com")
                        .license(new License().name("Apache 2.0")
                                .url("http://doc.xiaominfo.com"))
                ).addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
                .components(new Components().addSecuritySchemes(HttpHeaders.AUTHORIZATION, new SecurityScheme()
                        .name(HttpHeaders.AUTHORIZATION).type(SecurityScheme.Type.HTTP).scheme("bearer")));
    }


}
